package com.estate.house.controller;

import com.estate.bean.Building;
import com.estate.house.service.BuildingService;
import com.estate.util.JsonResult;
import com.estate.util.ResultTool;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/building")
public class BuildingController {
    @Resource
    private BuildingService buildingService;

    @GetMapping("/list/{buildingId}")
    public JsonResult findById(@PathVariable("buildingId") String buildingId) {
        return buildingService.findById(buildingId);
    }

    @GetMapping("/listByPage/{page}/{size}")
    public JsonResult listByPage(@PathVariable("page") int page, @PathVariable("size") int size) {
        log.info("page:{},size:{}", page, size);
        JsonResult result = buildingService.listByPage(page, size);
        log.info("result:{}", result);
        return result;
    }

    @PostMapping("/save")
    public JsonResult save(Building building) {
        log.info("building:{}", building);
        JsonResult result = buildingService.addBuilding(building);
        log.info("result:{}", result);
        return result;
    }

    @PutMapping("/update")
    public JsonResult update(Building building) {
        log.info("building:{}", building);
        JsonResult result = buildingService.updateBuilding(building);
        log.info("result:{}", result);
        return result;
    }

    @DeleteMapping("/delete")
    public JsonResult delete(@RequestParam("id") String id) {
        log.info("id:{}", id);
        return buildingService.deleteBuilding(id);
    }
}
